﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SubSonic;
using CXDB;
using Coolite.Ext.Web;

namespace Search.HR
{
    public partial class Search_Hr_View : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["id"] != null)
            {
                string id = Request["id"];
                Query q = new Query(CxApply.Schema);
                q.AddWhere("id", id);
                q.AddWhere("uid", Cookies.getCookies("cuid"));
                q.SetSelectList("bossnod,dateadd(day,15,bosstime),guid");
                
                if (q.GetRecordCount() == 0)
                {
                    Err.Warning("没有该条记录！", MessageBox.Icon.ERROR);
                    return;
                }

                IDataReader dr = q.ExecuteReader();
                if (dr.Read())
                {
                    if (dr["bossnod"].ToString() == "0")
                    {
                        Err.Warning("请等待审核！", MessageBox.Icon.WARNING);
                        return;
                    }
                    if (dr["bossnod"].ToString() != "1")
                    {
                        Err.Warning("您的申请已被管理员拒绝，请重新申请！", MessageBox.Icon.WARNING);
                        return;
                    }
                    if (DateTime.Parse(dr[1].ToString()) <= DateTime.Now)
                    {
                        Err.Warning("您的申请已过期，请重新申请！", MessageBox.Icon.WARNING);
                        return;
                    }
                    //开始输出数据
                    Query query = new Query(VwStaffHrStep1.Schema);
                    query.AddWhere("guid", dr["guid"].ToString());
                    IDataReader r = query.ExecuteReader();
                    if (r.Read())
                    {
                        tftalktime.Text = r["talktime"].ToString();
                        tftalkcontent.Text = r["talkcontent"].ToString();
                        tfpunish_party_time.Text = r["punish_party_time"].ToString();
                        tfpunish_party_type.Text = r["punish_party_type"].ToString();
                        tfpunish_party_reason.Text = r["punish_party_reason"].ToString();
                        tfpunish_penal_time.Text = r["punish_penal_time"].ToString();
                        tfpunish_penal_type.Text = r["punish_penal_type"].ToString();
                        tfpunish_penal_reason.Text = r["punish_penal_reason"].ToString();
                        tfparty_problem.Text = r["party_problem"].ToString();
                        tfother_problem.Text = r["other_problem"].ToString();
                        //tfadept_masterid.Text = Username(r["adept_masterid"].ToString());
                        //tfadept_master_time.Text = r["adept_master_entering_time"].ToString();
                        //tfadept_master_status.Text = Status(r["adept_master_status"].ToString());
                        //tfadept_master_remark.Text = r["adept_master_remark"].ToString();
                        tfdept_master_id.Text = Username(r["dept_master_id"].ToString());
                        tfdept_master_time.Text = r["dept_master_entering_time"].ToString();
                        //tfdept_master_status.Text = Status(r["dept_master_status"].ToString());
                        tfdept_master_remark.Text = r["dept_master_remark"].ToString();
                        tfboss_userid.Text = Username(r["boss_userid"].ToString());
                        tfboss_time.Text = r["boss_time"].ToString();
                        //tfboss_status.Text = Status(r["boss_status"].ToString());
                        tfboss_remark.Text = r["boss_remark"].ToString();
                        tfed_username.Text = r["ed_username"].ToString();
                        tfed_deptname.Text = r["ed_deptname"].ToString();
                        //tfintime.Text = r["intime"].ToString();
                        //tfenter_username.Text = r["enter_username"].ToString();
                        //string[] str = CXFileUpload.show(new Guid(dr["guid"].ToString())).Split('$');
                        //tfzip.Text = str[1];
                        //tfzip.NavigateUrl = str[0];
                    }
                }


            }
        }
        protected string Username(string uid)
        {
            if(uid=="")
            {
                return "未指定";
            }
            Query q = new Query(CxUserBase.Schema);
            q.AddWhere("uid", uid);
            q.SetSelectList("username");
            return q.ExecuteScalar().ToString();
        }
        protected string Status(string s)
        {
            switch (s)
            {
                case "0":
                    return "未审核";
                    break;
                case "1":
                    return "同意";
                    break;
                case "2":
                    return "退回";
                    break;
                default:
                    break;
            }
            return "未知";
        }
    }
}